local extension = Package:new("yinshen")
extension.extensionName = "king"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["yinshen"] = "阴-神",
}

local yin__godxunyu = General(extension, "yin__shenxunyu", "god", 3)
local yin__tianzuo = fk.CreateTriggerSkill{
  name = "yin__tianzuo",
  anim_type = "defensive",
  events = {fk.GameStart, fk.PreCardEffect},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.PreCardEffect then
      return data.to == player.id and data.card.name == "raid_and_frontal_attack"
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local name = "raid_and_frontal_attack"
      local yin__tianzuo_derivecards = {{name, Card.Spade, 2}, {name, Card.Spade, 4}, {name, Card.Spade, 6}, {name, Card.Spade, 8},
      {name, Card.Club, 3},{name, Card.Club, 5},{name, Card.Club, 7},{name, Card.Club, 9},{name, Card.Spade, 2}, {name, Card.Spade, 4}, {name, Card.Spade, 6}, {name, Card.Spade, 8},
      {name, Card.Club, 3},{name, Card.Club, 5},{name, Card.Club, 7},{name, Card.Club, 9},{name, Card.Spade, 2}, {name, Card.Spade, 4}, {name, Card.Spade, 6}, {name, Card.Spade, 8},
      {name, Card.Club, 3},{name, Card.Club, 5},{name, Card.Club, 7},{name, Card.Club, 9}}
      for _, id in ipairs(U.prepareDeriveCards(room, yin__tianzuo_derivecards, "yin__tianzuo_derivecards")) do
        if room:getCardArea(id) == Card.Void then
          table.removeOne(room.void, id)
          table.insert(room.draw_pile, math.random(1, #room.draw_pile), id)
          room:setCardArea(id, Card.DrawPile, nil)
        end
      end
      room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
    else
      return true
    end
  end,
}
  local zhinang = { "ex_nihilo", "dismantlement", "nullification" }
  local yin__lingce = fk.CreateTriggerSkill{
  name = "yin__lingce",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return
      player:hasSkill(self) and
      data.card.type ~= Card.TypeEquip and
      ( table.contains(zhinang, data.card.trueName) or
        table.contains(player:getTableMark("@$yin__dinghan"), data.card.trueName) or
        data.card.trueName == "raid_and_frontal_attack")
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
  }
  local yin__dinghan = fk.CreateTriggerSkill{
  name = "yin__dinghan",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) then
      return false
    end

    if event == fk.TargetConfirming then
      return
        data.card.type ~= Card.TypeEquip and
        data.card.name ~= "raid_and_frontal_attack" and
        not table.contains(player:getTableMark("@$yin__dinghan"), data.card.trueName)
    else
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local room = player.room

      local yin__dinghanRecord = player:getTableMark("@$yin__dinghan")
      local allcardsName = {}
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        if card.type ~= Card.TypeEquip and not card.is_derived and not table.contains(yin__dinghanRecord, card.trueName) then
          table.insertIfNeed(allcardsName, card.trueName)
        end
      end

      local choices = {"Cancel"}
      if #allcardsName > 0 then
        table.insert(choices, 1, "yin__dinghan_addRecord")
      end
      if #yin__dinghanRecord > 0 then
        table.insert(choices, 2, "yin__dinghan_removeRecord")
      end
      local choice = room:askForChoice(player, choices, self.name)

      if choice == "Cancel" then
        return false
      end

      local cardName = room:askForChoice(player, choice == "yin__dinghan_addRecord" and allcardsName or yin__dinghanRecord, self.name)

      self.cost_data = { choice = choice, cardName = cardName }
    end

    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local yin__dinghanRecord = player:getTableMark("@$yin__dinghan")
    if event == fk.TargetConfirming then
      table.insert(yin__dinghanRecord, data.card.trueName)
      room:setPlayerMark(player, "@$yin__dinghan", yin__dinghanRecord)
      AimGroup:cancelTarget(data, player.id)
      return true
    else
      local costData = self.cost_data
      if costData.choice == "yin__dinghan_addRecord" then
        table.insert(yin__dinghanRecord, costData.cardName)
      else
        table.removeOne(yin__dinghanRecord, costData.cardName)
      end
      room:setPlayerMark(player, "@$yin__dinghan", #yin__dinghanRecord > 0 and yin__dinghanRecord or 0)
    end
  end,
  }
  yin__godxunyu:addSkill(yin__tianzuo)
  yin__godxunyu:addSkill(yin__lingce)
  yin__godxunyu:addSkill(yin__dinghan)
  Fk:loadTranslationTable{
  ["yin__shenxunyu"] = "神荀彧",
  ["yin__tianzuo"] = "天佐",
  [":yin__tianzuo"] = "锁定技，游戏开始时，将24张<a href='raid_and_frontal_attack_href'>【奇正相生】</a>加入牌堆；【奇正相生】对你无效。",
  ["yin__lingce"] = "灵策",
  [":yin__lingce"] = "锁定技，当非装备牌被使用时，若此牌的牌名属于<a href='bag_of_tricks'>智囊</a>牌名、〖定汉〗已记录的牌名或【奇正相生】时，你摸一张牌。",
  ["yin__dinghan"] = "定汉",
  [":yin__dinghan"] = "当你成为非装备牌牌的目标时，若此牌牌名未被记录，则记录此牌名，然后取消此目标；回合开始时，你可以增加或移除一种牌的牌名记录。",
  ["@$yin__dinghan"] = "定汉",
  ["yin__dinghan_addRecord"] = "增加牌名",
  ["yin__dinghan_removeRecord"] = "移除牌名",
  ["bag_of_tricks"] = "#\"<b>智囊</b>\" ：即【过河拆桥】【无懈可击】【无中生有】。",
  ["raid_and_frontal_attack_href"] = "【<b>奇正相生</b>】（♠2/♠4/♠6/♠8/♣3/♣5/♣7/♣9） 锦囊牌<br/>" ..
  "出牌阶段，对一名其他角色使用。当此牌指定目标后，你为其指定“奇兵”或“正兵”。"..
  "目标角色可以打出一张【杀】或【闪】，然后若其为：“正兵”目标且未打出【杀】，你对其造成1点伤害；“奇兵”目标且未打出【闪】，你获得其一张牌。",
}


local yin__godguojia = General(extension, "yin__godguojia", "god", 3)
local yin__godguojia_win = fk.CreateActiveSkill{ name = "yin__godguojia_win_audio" }
yin__godguojia_win.package = extension
Fk:addSkill(yin__godguojia_win)

local yin__godguojia2 = General(extension, "yin2__godguojia", "god", 3)
local yin__godguojia2Win = fk.CreateActiveSkill{ name = "yin2__godguojia_win_audio" }
yin__godguojia2Win.package = extension
Fk:addSkill(yin__godguojia2Win)
yin__godguojia2.hidden = true




local yin__godHuishi = fk.CreateActiveSkill{
  name = "yin__godHuishi",
  anim_type = "drawcard",
  prompt = "#yin__godHuishi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 
  end,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cardsJudged = {}
    while true do
      local parsePattern = table.concat(table.map(cardsJudged, function(card)
        return card:getSuitString()
      end), ",")
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|" .. (parsePattern == "" and "." or "^(" .. parsePattern .. ")"),
        skipDrop = true,
      }
      room:judge(judge)
      table.insert(cardsJudged, judge.card)
      if player.dead  or
        not table.every(cardsJudged, function(card)
          return card == judge.card or judge.card:compareSuitWith(card, true)
        end) or
        not room:askForSkillInvoke(player, self.name, nil, "#yin__godHuishi-ask")
      then
        break
      end
      room:changeMaxHp(player, 1)
      room:recover({who = player,  num = 1,  recoverBy = player,  skillName = self.name })
    end
    cardsJudged = table.filter(cardsJudged, function(card)
      return room:getCardArea(card.id) == Card.Processing
    end)
    if #cardsJudged == 0 then return end
      room:moveCardTo(cardsJudged, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, true, player.id)
    if #cardsJudged == 2 and player:getMark("yin__godHuishi-turn") < 1 then 
      player:addSkillUseHistory(self.name, -1)
      room:addPlayerMark(player, "yin__godHuishi-turn",1)
    end
  end,
}
local yin__tianyi = fk.CreateTriggerSkill{
  name = "yin__tianyi",
  anim_type = "support",
  events = {fk.Damaged,fk.MaxHpChanged},
  frequency = Skill.Wake,
  can_trigger = function(self, event, target, player, data)
    return
      player:hasSkill(self) and
      player:usedSkillTimes(self.name, Player.HistoryGame) < 1
  end,
  can_wake = function(self, event, target, player, data)
    return table.every(player.room.alive_players, function(p)
      return #player.room.logic:getActualDamageEvents(1, function(e)
        return e.data[1].to == p
      end, Player.HistoryGame) > 0
    end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.general == "yin__godguojia" then
      player.general = "yin2__godguojia"
      room:broadcastProperty(player, "general")
    elseif player.deputyGeneral == "yin__godguojia" then
      player.deputyGeneral = "yin2__godguojia"
      room:broadcastProperty(player, "deputyGeneral")
    end
    room:changeMaxHp(player, 2)
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name,
    })
      room:handleAddLoseSkills(player, "yin__zuoxing")
  end,
}
local yin__limitedHuishi = fk.CreateActiveSkill{
  name = "yin__limitedHuishi",
  anim_type = "support",
  frequency = Skill.Limited,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return true
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local wakeSkills = {}
      wakeSkills = table.map(table.filter(to.player_skills, function(s)
        return s.frequency == Skill.Wake and to:usedSkillTimes(s.name, Player.HistoryGame) < 1
      end), function(skill)
        return skill.name 
      end)
    if #wakeSkills > 0  then
      local choice = room:askForChoice(from, wakeSkills, self.name, "#yin__limitedHuishi-choice:"..to.id)
      room:addTableMarkIfNeed(to, "@yin__limitedHuishi", choice)
      room:addTableMarkIfNeed(to, MarkEnum.StraightToWake, choice)
    else
      to:drawCards(4, self.name)
    end
    room:changeMaxHp(from, -2)
    from:drawCards(4, self.name)
  end,
}
local yin__limitedHuishiClear = fk.CreateTriggerSkill{
  name = "#yin__limitedHuishiClear-clear",
  refresh_events = {fk.BeforeTriggerSkillUse},
  can_refresh = function(self, event, target, player, data)
    return
      target == player and
      data.willUse and
      data.skill.frequency == Skill.Wake and
      type(player:getMark("@yin__limitedHuishiClear")) == "table" and
      table.contains(player:getMark("@yin__limitedHuishiClear"), data.skill.name)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:removeTableMark(player, "@yin__limitedHuishiClear", data.skill.name)
    room:removeTableMark(player, MarkEnum.StraightToWake, data.skill.name)
  end,
}
local yin__zuoxing = fk.CreateViewAsSkill{
  name = "yin__zuoxing",
  prompt = "#yin__zuoxing",
  interaction = function()
    local mark = Self:getTableMark("yin__zuoxing-turn")
    local names, all_names = {} , {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card:isCommonTrick() and not card.is_derived and not table.contains(all_names, card.name) and not table.contains(mark, card.name) then
        table.insert(all_names, card.name)
        local to_use = Fk:cloneCard(card.name)
        if Self:canUse(to_use) and not Self:prohibitUse(to_use) then
          table.insert(names, card.name)
        end
      end
    end
    if #names > 0 then
    return UI.ComboBox {choices = names, all_choices = all_names}
    end
  end,
  enabled_at_play = function(self, player)
    return
      table.find(Fk:currentRoom().alive_players, function(p)
        return table.find({ p.general, p.deputyGeneral }, function(name) return player.maxHp > 1 end)
      end)
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,

  before_use = function(self, player, use)
    local room = player.room
      room:addTableMark(player, "yin__zuoxing-turn", use.card.name)
    if player.maxHp > 1 then
      room:changeMaxHp(player, -1)
    end
  end,
}
local yin__godguojia_lightningAudio = fk.CreateTriggerSkill{
  name = "#yin__godguojia_lightningAudio",
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "lightning" 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/king/audio/card/yin__godguojia_lightning")
    room:setEmotion(player, "./packages/standard_cards/image/anim/lightning")
  end,
}
local yin2__godguojia_lightningAudio = fk.CreateTriggerSkill{
  name = "#yin2__godguojia_lightningAudio",
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "lightning" 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/king/audio/card/yin2__godguojia_lightning")
    room:setEmotion(player, "./packages/standard_cards/image/anim/lightning")
  end,
}
local yin2__godguojia_ex_nihiloAudio = fk.CreateTriggerSkill{
  name = "#yin2__godguojia_ex_nihiloAudio",
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "ex_nihilo"
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/king/audio/card/yin2__godguojia_ex_nihilo")
    room:setEmotion(player, "./packages/standard_cards/image/anim/ex_nihilo")
  end,
}
yin__limitedHuishi:addRelatedSkill(yin__limitedHuishiClear)
yin__godguojia:addSkill(yin__godHuishi)
yin__godguojia:addSkill(yin__tianyi)
yin__godguojia:addSkill(yin__limitedHuishi)
yin__godguojia:addRelatedSkill(yin__zuoxing)
yin__godguojia:addSkill(yin__godguojia_lightningAudio)

yin__godguojia2:addSkill(yin__godHuishi.name)
yin__godguojia2:addSkill(yin2__godguojia_lightningAudio)
yin__godguojia2:addSkill(yin2__godguojia_ex_nihiloAudio)
yin__godguojia2:addSkill(yin__tianyi.name)
yin__godguojia2:addRelatedSkill(yin__zuoxing.name)
yin__godguojia2:addSkill(yin__limitedHuishi.name)

Fk:loadTranslationTable{
  ["yin__godguojia"] = "神郭嘉",
  ["yin2"] = "阴",
  ["yin2__godguojia"] = "神郭嘉",

  ["yin__godHuishi"] = "慧识",
  [":yin__godHuishi"] = "出牌阶段限一次，你可以判定，若结果与本次流程中的其他判定结果均不同，你可加1点"..
  "体力上限、恢复一点体力并重复此流程。最后你获得本次流程中所有生效的判定牌；每回合限一次：若判定牌的数量等于2，则此技能视为未发动过。",
  ["yin__tianyi"] = "天翊",
  [":yin__tianyi"] = "觉醒技，若所有存活角色于本局游戏内均受到过伤害，你加2点体力上限，回复1点体力，并获得技能“佐幸”。",
  ["yin__limitedHuishi"] = "辉逝",
  [":yin__limitedHuishi"] = "限定技，出牌阶段，你可以选择一名角色，若其有未发动过的觉醒技，你选择其中一项技能，"..
  "视为该角色满足其觉醒条件；否则其摸四张牌。最后你减2点体力上限，并摸两张牌。",
  ["yin__zuoxing"] = "佐幸",
  [":yin__zuoxing"] = "出牌阶段：你可以减1点体力上限，视为使用一张本回合未以此法用过的普通锦囊牌。",
  ["#yin__godHuishi"] = "你可进行判定，然后获得判定牌，其间你增加体力上限",
  ["#yin__godHuishi-ask"] = "慧识：你可以加1点体力上限并重复此流程",
  ["@yin__limitedHuishi"] = "辉逝",
  ["#yin__limitedHuishi-choice"] = "辉逝：选择 %src 一个觉醒技，视为满足觉醒条件",
  ["#yin__zuoxing"] = "佐幸：你可以减1点体力上限，视为使用一张普通锦囊牌",

  ["$yin__godHuishi1"] = "观滴水而知沧海，窥一举而察人心。",
  ["$yin__godHuishi2"] = "察才识贤，以翊公之事。",
  ["$yin__tianyi1"] = "明主既现，吾定极尽所能。",
  ["$yin__tianyi2"] = "今九州纷乱，当祈天翊佑。",
  ["$yin__zuoxing1"] = "借天秘力，佐公之事，感有荣焉。",
  ["$yin__zuoxing2"] = "且为明公巧借天时。",
  ["$yin__limitedHuishi1"] = "人亦如星，或居空而渺然，或为彗而明夜。",
  ["$yin__limitedHuishi2"] = "纵殒身祭命，亦要助明公大业。",
  ["yin__godguojia_lightningAudio"] = "身怀安世之任，何需忧心天妒？",
  ["~yin__godguojia"] = "未及引动天能，竟已要坠入轮回……",
  ["$yin__godguojia_win_audio"] = "吾智珠在握，万般险阻亦无虞。",


  ["$yin__godHuishi_yin2__godguojia1"] = "人心所向，未来之事，皆一睹而尽知。",
  ["$yin__godHuishi_yin2__godguojia2"] = "笑揽世间众生，坐观天行定数。",
  ["$yin__limitedHuishi_yin2__godguojia1"] = "寿数长短，不足与明公大事相较。",
  ["$yin__limitedHuishi_yin2__godguojia2"] = "目下万物，皆为成吾等之愿。",
  ["$yin__zuoxing_yin2__godguojia1"] = "借天秘力，佐公之事，感有荣焉。",
  ["$yin__zuoxing_yin2__godguojia2"] = "且为明公巧借天时。",
  ["$yin__tianyi_yin2__godguojia1"] = "明主既现，吾定极尽所能。",
  ["$yin__tianyi_yin2__godguojia2"] = "今九州纷乱，当祈天翊佑。",
  ["yin2__godguojia_lightningAudio"] = "且要看看，天命向谁。",
  ["yin2__godguojia_ex_nihiloAudio"] = "天命所属，自当多得。",
  ["~yin2__godguojia"] = "跻身勠力以报公，却先为天谴吗？",
  ["$yin2__godguojia_win_audio"] = "洞天而为，安有大事不成之理？",

}


local yin__godlvbu = General(extension, "yin__godlvbu", "god", 5)
  local yin__kuangbao = fk.CreateTriggerSkill{
  name = "yin__kuangbao",
  events = {fk.GameStart, fk.Damage, fk.Damaged},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return (event == fk.GameStart or target == player) and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@yin__baonu", event == fk.GameStart and 2 or data.damage)
  end,

  on_lose = function (self, player, is_death)
    if player:getMark("@yin__baonu") ~= 0 then
      player.room:setPlayerMark(player, "@yin__baonu", 0)
    end
  end,
  }
  local yin__wumou = fk.CreateTriggerSkill{
  name = "yin__wumou",
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return (event == fk.GameStart or target == player) and player:hasSkill(self)
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room

    local toVoid = {}
    for _, id in ipairs(room.draw_pile) do
      if table.contains({ "dismantlement", "snatch", "duel", "collateral", "ex_nihilo", "nullification", "savage_assault", "archery_attack", "god_salvation", "amazing_grace","fire_attack" ,"iron_chain"}, Fk:getCardById(id).name) then
        table.insert(toVoid, id)
      end
    end
    for _, id in ipairs(room.discard_pile) do
      if table.contains({ "dismantlement", "snatch", "duel", "collateral", "ex_nihilo", "nullification", "savage_assault", "archery_attack", "god_salvation", "amazing_grace","fire_attack" ,"iron_chain"}, Fk:getCardById(id).name) then
        table.insert(toVoid, id)
      end
    end

    for _, p in ipairs(room.alive_players) do
      for _, id in ipairs(p:getCardIds("hej")) do
        if table.contains({ "dismantlement", "snatch", "duel", "collateral", "ex_nihilo", "nullification", "savage_assault", "archery_attack", "god_salvation", "amazing_grace","fire_attack" ,"iron_chain"}, Fk:getCardById(id).name) then
          table.insert(toVoid, id)
        end
      end
    end

    if #toVoid > 0 then
      room:moveCardTo(toVoid, Card.Void, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
  }
  local yin__wuqian = fk.CreateActiveSkill{
  name = "yin__wuqian",
  prompt = "#yin__wuqian-active",
  anim_type = "offensive",
  can_use = function(self, player)
    return player:getMark("@yin__baonu") > 1
  end,
  card_num = 0,
  target_num = 1,
  target_filter = function(self, to_select, selected)
    return #selected < 1 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("@@yin__wuqian-turn") == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(player, "@yin__baonu", 2)
    room:addPlayerMark(target, "@@yin__wuqian-turn")
    room:handleAddLoseSkills(player, "wushuang", nil, true, false)
    room:addPlayerMark(target, fk.MarkArmorNullified)
  end
  }
  local y_wuqianCleaner = fk.CreateTriggerSkill{
  name = "#y_wuqianCleaner",
  mute = true,
  refresh_events = {fk.TurnEnd},
  can_refresh = function(_, _, target, player)
    return target == player and target:usedSkillTimes("yin__wuqian") > 0
  end,
  on_refresh = function(_, _, target)
    local room = target.room
    room:handleAddLoseSkills(target, "-wushuang", nil, true, false)
    table.forEach(room.alive_players, function(p)
      if p:getMark("@@yin__wuqian-turn") > 0 then room:removePlayerMark(p, fk.MarkArmorNullified) end
    end)
  end,
  }
  yin__wuqian:addRelatedSkill(y_wuqianCleaner)
  local yin__shenfen = fk.CreateActiveSkill{
  name = "yin__shenfen",
  anim_type = "offensive",
  can_use = function(self,  player, effect,room)
    return  player:getMark("@yin__baonu") > 11
  end,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player, "@yin__baonu", 12)
    local targets = room:getOtherPlayers(player, true)
    room:doIndicate(effect.from, table.map(targets, Util.IdMapper))
    table.forEach(targets, function(p)
      if not p.dead then room:damage{ from = player, to = p, damage = 1, skillName = self.name } end
    end)
    table.forEach(targets, function(p)
      if not p.dead then p:throwAllCards("e") end
    end)
    table.forEach(targets, function(p)
      if not p.dead then
        room:askForDiscard(p, 4, 4, false, self.name, false)
      end
    end)
    if not player.dead then player:turnOver() end
  end
  }
  yin__godlvbu:addSkill(yin__kuangbao)
  yin__godlvbu:addSkill(yin__wumou)
  yin__godlvbu:addSkill(yin__wuqian)
  yin__godlvbu:addSkill(yin__shenfen)
  yin__godlvbu:addRelatedSkill("wushuang")
  Fk:loadTranslationTable{
    ["yin__godlvbu"] = "神吕布",
    ["yin__kuangbao"] = "狂暴",
    [":yin__kuangbao"] = "锁定技，游戏开始时，你获得2枚“暴怒”；当你造成或受到1点伤害后，你获得1枚“暴怒”。",
    ["yin__wumou"] = "无谋",
    [":yin__wumou"] = "锁定技，游戏开始时，你将牌堆、弃牌堆和所有角色区域内的普通锦囊牌移出游戏。",
    ["yin__wuqian"] = "无前",
    [":yin__wuqian"] = "出牌阶段，你可以获得2枚“暴怒”并选择一名此回合内未以此法选择过的其他角色，你于此回合内拥有〖无双〗且其防具技能于此回合内无效。",
    ["yin__shenfen"] = "神愤",
    [":yin__shenfen"] = "出牌阶段，你可以弃12枚“暴怒”并选择所有其他角色，对这些角色各造成1点伤害，然后这些角色各弃置其装备区里的所有牌，各弃置四张手牌。然后你翻面。",

    ["@yin__baonu"] = "暴怒",
    ["@@yin__wuqian-turn"] = "无前",
    ["#yin__wuqianCleaner"] = "无前",
    ["#yin__wuqian-active"] = "发动 无前，获得2枚暴怒，令一名角色的防具无效，且本回合你获得〖无双〗",
    ["#yin__shenfen-active"] = "发动 神愤，弃6枚暴怒，对所有角色造成伤害",
}
local yin__godzhangliao = General(extension, "yin__shenzhangliao", "god", 4)

  local yin__duorui = fk.CreateTriggerSkill{
  name = "yin__duorui",
  anim_type = "control",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play  and
     data.to ~= player and not data.to.dead
  end,
  on_use = function(self, event, _, player, data)
    local room = player.room
    local target = data.to
    if player.dead or target.dead then return false end
    local skills = {}
    local ban_types = {Skill.Limited, Skill.Wake, Skill.Quest}
    for _, skill_name in ipairs(Fk.generals[target.general]:getSkillNameList()) do
      local skill = Fk.skills[skill_name]
      if not (skill.lordSkill or table.contains(ban_types, skill.frequency)) then
        table.insertIfNeed(skills, skill_name)
      end
    end
    if target.deputyGeneral and target.deputyGeneral ~= "" then
      for _, skill_name in ipairs(Fk.generals[target.deputyGeneral]:getSkillNameList()) do
        local skill = Fk.skills[skill_name]
        if not (skill.lordSkill or table.contains(ban_types, skill.frequency)) then
          table.insertIfNeed(skills, skill_name)
        end
      end
    end
    if #skills == 0 then return false end
    local choice = room:askForChoice(player, skills, self.name, "#yin__duorui-skill::" .. data.to.id, true)
    local mark = type(target:getMark("yin__duorui_target")) == "table" and target:getMark("yin__duorui_target") or {}
    table.insert(mark, choice)
    room:setPlayerMark(target, "yin__duorui_target", mark)
    room:setPlayerMark(target, "@yin__duorui_target", choice)
    if player:hasSkill(choice, true) then return false end
    local mark2 = type(player:getMark("yin__duorui_source")) == "table" and player:getMark("yin__duorui_source") or {}
    table.insert(mark2, {target.id, choice})
    room:setPlayerMark(player, "yin__duorui_source", mark2)
    room:setPlayerMark(player, "@yin__duorui_source", choice)
    room:handleAddLoseSkills(player, choice, nil, true, true)
  end,

  refresh_events = {fk.AfterTurnEnd, fk.BuryVictim},
  can_refresh = Util.TrueFunc,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if player == target then
      room:setPlayerMark(player, "yin__duorui_target", 0)
      room:setPlayerMark(player, "@yin__duorui_target", 0)
    end
    local mark = player:getMark("yin__duorui_source")
    if type(mark) ~= "table" then return false end
    local clear_skills = {}
    local mark2 = {}
    for _, duorui_info in ipairs(mark) do
      if duorui_info[1] == target.id then
        table.insertIfNeed(clear_skills, duorui_info[2])
      else
        table.insertIfNeed(mark2, duorui_info)
      end
    end
    if #clear_skills > 0 then
      if #mark2 > 0 then
        room:setPlayerMark(player, "yin__duorui_source", mark2)
        room:setPlayerMark(player, "@yin__duorui_source", mark2[#mark2][2])
      else
        room:setPlayerMark(player, "yin__duorui_source", 0)
        room:setPlayerMark(player, "@yin__duorui_source", 0)
      end
      room:handleAddLoseSkills(player, "-"..table.concat(clear_skills, "|-"), nil, true, false)
    end
  end,
  }
  local yin__duorui_invalidity = fk.CreateInvaliditySkill {
  name = "#yin__duorui_invalidity",
  invalidity_func = function(self, from, skill)
    local mark = from:getMark("yin__duorui_target")
    return type(mark) == "table" and table.contains(mark, skill.name)
  end
  }
  yin__duorui:addRelatedSkill(yin__duorui_invalidity)
  local yin__zhiti = fk.CreateTriggerSkill{
  name = "yin__zhiti",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local num = #table.filter(player.room.alive_players, function (p) return p:isWounded() end)
      if num > 0 then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = #table.filter(player.room.alive_players, function (p) return p:isWounded() end)
    if event == fk.DrawNCards then
      data.n = data.n + num
    end
  end,
  }
  local yin__zhiti_maxcards = fk.CreateMaxCardsSkill{
  name = "#yin__zhiti_maxcards",
  correct_func = function(self, player)
    local n = 0
    local players = Fk:currentRoom().alive_players
    if player:hasSkill(yin__zhiti) and table.find(players, function (p) return p:isWounded() end) then
      local num = #table.filter(players, function (p) return p:isWounded() end)
      n = num
    end
    if player:isWounded() then
      for _, p in ipairs(players) do
        if p:hasSkill(yin__zhiti)  then
          n = n - 1
        end
      end
    end
    return n
  end,
  }
  local yin__zhiti_trigger = fk.CreateTriggerSkill{
  name = "#yin__zhiti_trigger",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local num = #table.filter(player.room.alive_players, function (p) return p:isWounded() end)
    return target == player and player.phase == Player.Play and player:hasSkill("yin__zhiti") and data.card.type ~=Card.TypeEquip and player:getMark("yin__zhiti-phase") <= num
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsive = true
  end,
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("yin__zhiti", true) and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "yin__zhiti-phase", 1)
  end,
  }
  yin__zhiti:addRelatedSkill(yin__zhiti_maxcards)
  yin__zhiti:addRelatedSkill(yin__zhiti_trigger)
  yin__godzhangliao:addSkill(yin__duorui)
  yin__godzhangliao:addSkill(yin__zhiti)
  Fk:loadTranslationTable {
  ["yin__shenzhangliao"] = "神张辽",
  ["yin__duorui"] = "夺锐",
  [":yin__duorui"] = "当你于出牌阶段内对一名其他角色造成伤害后，你可以选择该角色的武将牌上的一个技能，"..
  "限定技、觉醒技、使命技、主公技除外），令其于其下回合结束之前此技能无效，然后你于其下回合结束或其死亡之前拥有此技能。",
  ["yin__zhiti"] = "止啼",
  [":yin__zhiti"] = "锁定技，场上除你外已受伤的角色手牌上限-1；"..
  "若场上存在受伤的角色数：那么你的手牌上限+n；摸牌阶段，你多摸n张牌；回合开始时，你使用的前n张牌不可响应。(n为受伤角色数)",
  ["#yin__duorui-choice"] = "是否发动 夺锐，夺取%dest一个技能",
  ["#yin__duorui-skill"] = "夺锐：选择%dest的一个技能令其无效，且你获得此技能",
  ["@yin__duorui_source"] = "夺锐",
  ["@yin__duorui_target"] = "被夺锐",

  ["$yin__duorui1"] = "天下雄兵之锐，吾一人可尽夺之！",
  ["$yin__duorui2"] = "夺旗者勇，夺命者利，夺锐者神！",
  ["$yin__zhiti1"] = "江东小儿，安敢啼哭？",
  ["$yin__zhiti2"] = "娃闻名止啼，孙损十万休。",

}

local yin__godsunce = General(extension, "yin__godsunce", "god", 1, 6)
  local yin__yingba = fk.CreateActiveSkill{
  name = "yin__yingba",
  anim_type = "offensive",
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return Self.id ~= to_select 
  end,
  on_use = function(self, room, effect)
    local to = room:getPlayerById(effect.tos[1])
    room:changeMaxHp(to, -1)
    room:addPlayerMark(to, "@yin__yingba_pingding")

    room:changeMaxHp(room:getPlayerById(effect.from), -1)
  end,
  }
  local yin__yingbaBuff = fk.CreateTargetModSkill{
  name = "#yin__yingba-buff",
  bypass_distances =  function(self, player, skill, card, to)
    return player:hasSkill("yin__yingba") and to and to:getMark("@yin__yingba_pingding") > 0
  end,
  }
  local yin__fuhai = fk.CreateTriggerSkill{
  name = "yin__fuhai",
  events = {fk.TargetSpecified, fk.Death},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.TargetSpecified then
      return target == player and player.room:getPlayerById(data.to):getMark("@yin__yingba_pingding") > 0
    else
      return player.room:getPlayerById(data.who):getMark("@yin__yingba_pingding") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      data.disresponsiveList = data.disresponsiveList or {}
      table.insert(data.disresponsiveList, data.to)
        player:drawCards(1, self.name)
    else
      local pingdingNum = target:getMark("@yin__yingba_pingding")
      room:changeMaxHp(player, pingdingNum)
      player:drawCards(pingdingNum, self.name)
    end
  end,
  }
  local yin__pinghe = fk.CreateTriggerSkill{
  name = "yin__pinghe",
  events = {fk.DamageInflicted},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      player:hasSkill(self) and
      (player.maxHp > 1 or
      not player:isKongcheng()) and
      data.from and
      data.from ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices ={}
    if player.maxHp > 1 then
      table.insert(choices, "yin__pinghe-losemaxhp")
    if not player:isKongcheng() then
      table.insert(choices, "yin__pinghe-give")
    end
    if #choices > 0 then 
      local choice = room:askForChoice(player, choices, self.name, nil, nil, {"yin__pinghe-losemaxhp", "yin__pinghe-give"})
        if choice == "yin__pinghe-losemaxhp" then
          room:changeMaxHp(player, -1)
        else
          local tos, cardId = room:askForChooseCardAndPlayers(player, table.map(room:getOtherPlayers(player, false), function(p)
            return p.id end), 1, 1, ".|.|.|hand", "#yin__pinghe-give", self.name, false, true )
          room:obtainCard(tos[1], cardId, false, fk.ReasonGive)
        end
    if player:hasSkill(yin__yingba, true) and data.from:isAlive() then
      room:addPlayerMark(data.from, "@yin__yingba_pingding")
    end
  end
    end
    return true
  end,
  }
  local yin__pingheBuff = fk.CreateMaxCardsSkill {
  name = "#yin__pinghe-buff",
  frequency = Skill.Compulsory,
  fixed_func = function(self, player)
    return player:hasSkill("yin__pinghe") and player:getLostHp() or nil
  end
  }
  local yin__yinghun = fk.CreateTriggerSkill{
  name = "yin__yinghun",
  events = { fk.AfterCardsMove },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
    if player.phase ~= Player.Discard then return false end
    local room = player.room
    local cards = {}
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason == fk.ReasonDiscard then
        for _, info in ipairs(move.moveInfo) do
          if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
          room:getCardArea(info.cardId) == Card.DiscardPile then
            table.insertIfNeed(cards, info.cardId)
          end
        end
      end
    end
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end
    end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    if #cards > 0 then
      room:changeMaxHp(player, #cards)
      room:drawCards(player,#cards, self.name)
    end
    end,
  }
  yin__yingba:addRelatedSkill(yin__yingbaBuff)
  yin__pinghe:addRelatedSkill(yin__pingheBuff)
  yin__godsunce:addSkill(yin__yingba)
  yin__godsunce:addSkill(yin__fuhai)
  yin__godsunce:addSkill(yin__pinghe)
  yin__godsunce:addSkill(yin__yinghun)
  local yin__godsunce_win = fk.CreateActiveSkill{ name = "yin__godsunce_win_audio" }
    yin__godsunce_win.package = extension
  Fk:addSkill(yin__godsunce_win)
  Fk:loadTranslationTable{
  ["yin__godsunce"] = "神孙策",
  ["yin__yingba"] = "英霸",
  [":yin__yingba"] = "出牌阶段限一次，你可以令一名其他角色减1点体力上限，并令其获得一枚“平定”标记，然后你减1点体力上限；"..
  "你对拥有“平定”标记的角色使用牌无距离限制。",
  ["yin__fuhai"] = "覆海",
  [":yin__fuhai"] = "锁定技，①当你使用牌指定拥有“平定”标记的角色为目标后，其不能响应此牌，且你摸一张牌；②当拥有“平定”标记的角色死亡时，你增加X点体力上限并摸X张牌。（X为其“平定”标记数）",
  ["yin__pinghe"] = "冯河",
  [":yin__pinghe"] = "锁定技，你的手牌上限基值为你已损失的体力值；当你受到其他角色造成的伤害时，若你的体力上限大于1或你有手牌，你防止此伤害，"..
  "减1点体力上限或将一张手牌交给一名其他角色，然后若你有技能〖英霸〗，伤害来源获得一枚“平定”标记。",
  ["yin__yinghun"] = "英魂",
  [":yin__yinghun"]= "你的弃牌阶段结束时，你可以摸x张牌并获得x点体力上限（x为你弃牌阶段内弃置的牌数）。",
  ["#yin__pinghe-give"] = "冯河：请交给一名其他角色一张手牌",
  ["@yin__yingba_pingding"] = "平定",

  ["yin__pinghe-losemaxhp"] = "减1点体力上限", 
  ["yin__pinghe-give"] = "交出一张手牌",

  ["$yin__yingba1"] = "从我者可免，拒我者难容！",
  ["$yin__yingba2"] = "卧榻之侧，岂容他人鼾睡！",
  ["$yin__fuhai1"] = "翻江复蹈海，六合定乾坤！",
  ["$yin__fuhai2"] = "力攻平江东，威名扬天下！",
  ["$yin__pinghe1"] = "不过胆小鼠辈，吾等有何惧哉！",
  ["$yin__pinghe2"] = "只可得胜而返，岂能败战而归！",
  ["~yin__godsunce"] = "无耻小人！竟敢暗算于我……",

  ["$yin__godsunce_win_audio"] = "平定三郡，稳据江东！",
}

local yin__godjiangwei = General(extension, "yin__godjiangwei", "god", 4)
  local yin__tianren = fk.CreateTriggerSkill {
  name = "yin__tianren",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile  then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId)
            if card.type == Card.TypeBasic or card:isCommonTrick() then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = 0
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card.type == Card.TypeBasic or card:isCommonTrick() then
            x = x + 1
          end
        end
      end
    end
    room:addPlayerMark(player, "@yin__tianren", x)
    while player:getMark("@yin__tianren") >= player.maxHp do
      room:removePlayerMark(player, "@yin__tianren", player.maxHp)
      room:changeMaxHp(player, 1)
      if player.dead then return false end
      player:drawCards(2, self.name)
      if player.dead then return false end
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@yin__tianren", 0)
  end,
  }
  Fk:addPoxiMethod{
  name = "yin__jiufa",
  card_filter = function(to_select, selected, data)
    if table.contains(data[2], to_select) then return true end
    local number = Fk:getCardById(to_select).number
    return table.every(data[2], function (id)
      return Fk:getCardById(id).number ~= number
    end) and not table.every(data[1], function (id)
      return id == to_select or Fk:getCardById(id).number == number
    end)
  end,
  feasible = function(selected)
    return true
  end,
  }
  local yin__jiufa = fk.CreateTriggerSkill{
  name = "yin__jiufa",
  events = {fk.CardUsing, fk.CardResponding},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) 
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@yin__jiufa", 1)
    if player:getMark("@yin__jiufa") < 9 or not room:askForSkillInvoke(player, self.name, nil, "#yin__jiufa-invoke") then return false end
    room:setPlayerMark(player, "@yin__jiufa", 0)
    local card_ids = U.turnOverCardsFromDrawPile(player, 9, self.name)
    local get, throw = {}, {}
    local number_table = {}
    for _ = 1, 13, 1 do
      table.insert(number_table, 0)
    end
    for _, id in ipairs(card_ids) do
      local x = Fk:getCardById(id).number
      number_table[x] = number_table[x] + 1
      if number_table[x] == 2 then
        table.insert(get, id)
      else
        table.insert(throw, id)
      end
    end
    local result = room:askForArrangeCards(player, self.name, {card_ids},
    "#yin__jiufa", false, 0, {9, 9}, {0, #get}, ".", "yin__jiufa", {throw, get})
    throw = result[1]
    get = result[2]
    if #get > 0 then
      room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
    end
    room:cleanProcessingArea(card_ids, self.name)
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@yin__jiufa", 0)
  end,
  }
  local yin__pingxiang = fk.CreateActiveSkill{
  name = "yin__pingxiang",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  prompt = "#yin__pingxiang",
  can_use = function(self, player)
    return player.maxHp > 9 
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:changeMaxHp(player, -9)
    if player.dead then return end
    for i = 1, 9, 1 do
      if player.dead or not U.askForUseVirtualCard(room, player, "fire__slash", nil, self.name, "#yin__pingxiang-slash:::" .. i, true, true) then
        break
      end
    end
  end,
  }
  yin__godjiangwei:addSkill(yin__tianren)
  yin__godjiangwei:addSkill(yin__jiufa)
  yin__godjiangwei:addSkill(yin__pingxiang)
  Fk:loadTranslationTable{
  ["yin__godjiangwei"] = "神姜维",

  ["yin__tianren"] = "天任",
  [":yin__tianren"] = "锁定技，当一张基本牌或普通锦囊牌置入弃牌堆后，你获得1个“天任”标记，"..
  "然后若“天任”标记数不小于X，你移去X个“天任”标记，加1点体力上限并摸两张牌（X为你的体力值）。",
  ["yin__jiufa"] = "九伐",
  [":yin__jiufa"] = "当你每累计使用或打出九张牌后，你可以亮出牌堆顶的九张牌，然后选择并获得其中每个点数的牌各一张（最多8张）。",
  ["yin__pingxiang"] = "平襄",
  [":yin__pingxiang"] = "出牌阶段，若你的体力上限大于9，你可以减9点体力上限。"..
  "然后你可以视为使用至多九张火【杀】。",

  ["@yin__tianren"] = "天任",
  ["@yin__jiufa"] = "九伐",
  ["#yin__jiufa-invoke"] = "九伐：是否亮出牌堆顶九张牌，获得每个点数的牌各一张！（最多8张）",
  ["#yin__pingxiang"] = "平襄：你可以减9点体力上限，视为使用至多九张火【杀】！",
  ["#yin__pingxiang-slash"] = "平襄：你可以视为使用火【杀】（第%arg张，共9张）！",

  ["#yin__jiufa"] = "九伐：从亮出的牌中选择并获得其中每个点数的牌各一张",
  ["AGCards"] = "亮出的牌",
  ["toGetCards"] = "获得的牌",

  ["$tianren1"] = "举石补苍天，舍我更复其谁？",
  ["$tianren2"] = "天地同协力，何愁汉道不昌？",
  ["$jiufa1"] = "九伐中原，以圆先帝遗志。",
  ["$jiufa2"] = "日日砺剑，相报丞相厚恩。",
  ["$pingxiang1"] = "策马纵慷慨，捐躯抗虎豺。",
  ["$pingxiang2"] = "解甲事仇雠，竭力挽狂澜。",
  ["~godjiangwei"] = "武侯遗志，已成泡影矣……",
}


--[[local yin__godpeixiu = General(extension, "yin__godpeixiu", "god", 3)
  local yin__tuce = fk.CreateTriggerSkill{
  name = "yin__tuce",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return
      player:hasSkill(self) and card.type ~= Card.TypeEquip and
      not data.card:isVirtual() 
  end,
  on_use = function(self, event, target, player, data)
    local n = data.card.number
    if data.card.number == n and player:getMark("@@yin__dingdian"..n) > 0 then
      player:drawCards(1, self.name)
    end
  end,
  }
  local yin__dingdian = fk.CreateTriggerSkill{
  name = "yin__dingdian",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) and card.type == Card.TypeEquip then
      return false
    end

    if event == fk.TargetConfirming then
      local n = data.card.number
      return

        not player:getMark("@@yin__dingdian"..n)
    else
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local room = player.room

      local yin__dingdianRecord = player:getMark("@@yin__dingdian")
      local alln = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13"}
      for _, card in ipairs(Fk:getAllCardIds()) do
        local n = Fk:getCardById().number   
        if  not card.is_derived and not player:getMark("@@yin__dingdian"..n) then
          player:getMark("@@yin__dingdian"..n)
        end
      end

      local choices = {"Cancel"}
      if #alln > 0 then
        table.insert(choices, 1, "yin__dingdian_addRecord")
      end
      if #yin__dingdianRecord > 0 then
        table.insert(choices, 2, "yin__dingdian_removeRecord")
      end
      local choice = room:askForChoice(player, choices, self.name)

      if choice == "Cancel" then
        return false
      end

      local cardnumber = room:askForChoice(player, choice == "yin__dingdian_addRecord" and alln or yin__dingdianRecord, self.name)

      self.cost_data = { choice = choice, cardnumber = cardnumber }
    end

    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      local n = data.card.number
      if player:getMark("@@yin__dingdian"..n) == 0 then
        player:getMark("@@yin__dingdian"..n)
    else
      local costData = self.cost_data
      if costData.choice == "yin__dingdian_addRecord" then
        player:addMark("@@yin__dingdian"..costData.cardnumber)
      else
        player:removeMark("@@yin__dingdian"..costData.cardnumber) 
      end
    end
    end
  end,
  }
  yin__godpeixiu:addSkill(yin__tuce)
  yin__godpeixiu:addSkill(yin__dingdian)
  Fk:loadTranslationTable{
  ["yin__godpeixiu"] = "神裴秀",

  ["yin__tuce"] = "图策",
  [":yin__tuce"] = "锁定技，当非虚拟且非转化的牌被使用时，若此牌的点数〖定点〗已记录的点数时，你摸一张牌。",
  ["yin__dingdian"] = "定点",
  [":yin__dingdian"] = "当你成为牌的目标时，若此牌的点数未被记录，则记录此点数，然后取消此目标；回合开始时，你可以增加或移除一种点数记录。",
  ["@$yin__dingdian"] = "定点",
  ["yin__dingdian_addRecord"] = "增加点数",
  ["yin__dingdian_removeRecord"] = "移除点数",
}]]

local yin__godganning = General(extension, "yin__godganning", "god", 4)
local yin__poxi = fk.CreateActiveSkill{--
  name = "yin__poxi",
  anim_type = "control",
  prompt = "#yin__poxi-prompt",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
  end,
  card_filter = function() return false end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id 
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local player_hands = player:getCardIds("h")
    local target_hands = target:getCardIds("h")
    local cards = room:askForPoxi(player, "poxi_discard", {
      { player.general, player_hands },
      { target.general, target_hands },
    }, nil, true)
    if #cards == 0 then return end
    local cards1 = table.filter(cards, function(id) return table.contains(player_hands, id) end)
    local cards2 = table.filter(cards, function(id) return table.contains(target_hands, id) end)
    local moveInfos = {}
    if #cards1 > 0 then
      table.insert(moveInfos, {
        from = player.id,
        ids = cards1,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonDiscard,
        proposer = effect.from,
        skillName = self.name,
      })
    end
    if #cards2 > 0 then
      table.insert(moveInfos, {
        from = target.id,
        ids = cards2,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonDiscard,
        proposer = effect.from,
        skillName = self.name,
      })
    end
    room:moveCards(table.unpack(moveInfos))
    if player.dead then return false end

    if #cards1 == 0 then
      room:changeMaxHp(target, -1)
    elseif #cards1 == 3  then
      room:changeMaxHp(player, 1)
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif #cards1 == 2  then
      room:damage({
        from = player,
        to = target ,
        num = 1,
        skillName = self.name
      })
    elseif #cards1 == 1 then
      room:addPlayerMark(target, "@@yin__poxi",1)
    elseif #cards1 == 4 then
      room:drawCards(player, 8, self.name)
    end
    return false
  end,
}
local yin__poxi_delay = fk.CreateTriggerSkill{
  name = "#yin__poxi_delay",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player == target and player.phase == Player.Start and player:getMark("@@yin__poxi") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:skip(Player.Play)
    room:setPlayerMark(player, "@@yin__poxi", 0)
  end,
}

local yin_jieying = fk.CreateTriggerSkill{
  name = "yin_jieying",
  anim_type = "drawcard",
  events = {fk.DrawNCards, fk.EventPhaseStart, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.TurnStart then
      return player == target and table.every(player.room.alive_players, function (p)
        return p:getMark("@@yin__jieying_camp") == 0 end)
    elseif event == fk.EventPhaseStart and target.phase ~= Player.Finish then
      return false
    end
    return target:getMark("@@yin__jieying_camp") > 0
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart and player == target then
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper),
      1, 1, "#yin_jieying-choose", self.name, true)
      if #to > 0 then
        self.cost_data = {tos = to}
        return true
      end
      return false
    end
    self.cost_data = {}
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:addPlayerMark(player, "@@yin__jieying_camp")
    elseif event == fk.DrawNCards then
      data.n = data.n + 1
    elseif event == fk.EventPhaseStart then
      if player == target then
        local tar = room:getPlayerById(self.cost_data.tos[1])
        room:setPlayerMark(player, "@@yin__jieying_camp", 0)
        room:addPlayerMark(tar, "@@yin__jieying_camp")
      else
        room:setPlayerMark(target, "@@yin__jieying_camp", 0)
        room:addPlayerMark(player, "@@yin__jieying_camp")
        if not target:isKongcheng() then
          room:obtainCard(player.id, target:getCardIds(Player.Hand), false, fk.ReasonPrey)
        end
      end
    end
    return false
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
    if table.every(room.alive_players, function (p) return not p:hasSkill(self, true) end) then
      for _, p in ipairs(room.alive_players) do
        if p:getMark("@@yin__jieying_camp") > 0 then
          room:setPlayerMark(p, "@@yin__jieying_camp", 0)
        end
      end
    end
  end,
}

local yin__jieying_discard = fk.CreateTriggerSkill{
  name = "#yin__jieying_discard",
  mute = true,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return player == target and player.phase == Player.Play and player:getMark("@@yin__jieying_camp") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:skip(Player.Discard)
  end,
}

local yin__jieying_targetmod = fk.CreateTargetModSkill{
  name = "#yin__jieying_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@@yin__jieying_camp") > 0 and scope == Player.HistoryPhase then
      return #table.filter(Fk:currentRoom().alive_players, function (p) return p:hasSkill(yin_jieying) end)
    end
  end,
}

yin_jieying:addRelatedSkill(yin__jieying_targetmod)
yin_jieying:addRelatedSkill(yin__jieying_discard)
yin__godganning:addSkill(yin__poxi)
yin__poxi:addRelatedSkill(yin__poxi_delay)
yin__godganning:addSkill(yin_jieying)
Fk:loadTranslationTable{
  ["yin__godganning"] = "神甘宁",

  ["yin__poxi"] = "魄袭",
  [":yin__poxi"] = "出牌阶段限一次，你可以观看一名其他角色的手牌，然后你可以弃置你与其手里共计四张不同花色的牌。若如此做，根据此次弃置你的牌数量执行以下效果：没有，其体力上限减1；一张，其跳过下个出牌阶段你且本回合手牌上限+1；两张：你对其造成1点伤害；三张，加一点体力上限，恢复一点体力；四张，摸八张牌。",
  ["yin_jieying"] = "劫营",
  [":yin_jieying"] = "回合开始时，若没有角色有“营”标记，你获得一个“营”标记；结束阶段你可以将“营”标记交给一名其他角色；有“营”的角色摸牌阶段多摸一张牌、使用【杀】的次数上限+1、跳过弃牌阶段。有“营”的其他角色的结束阶段，你获得其“营”标记及所有手牌。",

  ["yin__poxi_discard"] = "魄袭",
  ["#yin__poxi-prompt"] = "魄袭：选择一名有手牌的其他角色，并可弃置你与其手牌中共计四张花色各不相同的牌",
  ["@@yin__jieying_camp"] = "营",
  ["#yin__poxi-choose"] = "魄袭：从双方的手牌中选出四张不同花色的牌弃置，或者点取消",
  ["#yin__poxi-ask"] = "魄袭：弃置双方手里四张不同花色的牌",
  ["#yin_jieying-choose"] = "劫营：你可将营标记交给其他角色",
  ["@@yin__poxi"] = "魄袭-跳过出牌",
}



--[[local yin__godguozhao = General(extension, "yin__godguozhao", "god", 3)
local yin__pianchong = fk.CreateTriggerSkill{
  name = "yin__pianchong",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)  
  end,
  on_use = function(self, event, target, player, data)
    local suit = data.card.suit
    if player:getMark("@yin__spade") > 0 and suit == "spade" then
      player:drawCards(1, self.name)
    elseif player:getMark("@yin__heart") > 0 and suit == "heart" then
      player:drawCards(1, self.name)
    elseif player:getMark("@yin__club") > 0 and suit == "club" then
      player:drawCards(1, self.name)
    elseif player:getMark("@yin__diamond") > 0 and suit == "diamond" then
      player:drawCards(1, self.name)
    end
  end,
}
local yin__zunwei = fk.CreateTriggerSkill{
  name = "yin__zunwei",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self)  then
      return false
    end

    if event == fk.TargetConfirming then
      local suit = data.card.suit
      if  suit == "spade" then
        return  player:getMark("@yin__spade")==0
      elseif suit == "heart" then
        return  player:getMark("@yin__heart")==0
      elseif  suit == "club" then
        return  player:getMark("@yin__club") == 0
      elseif suit == "diamond" then
        return  player:getMark("@yin__diamond") == 0
      end
    else
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local room = player.room
      local choices1 = {"Cancel"}
      if player:getMark("@yin__spade") > 0 or player:getMark("@yin__heart") > 0 or player:getMark("@yin__club") > 0 or player:getMark("@yin__diamond") > 0 then
        table.insert(choices1, 2,"remove_suit")
      elseif player:getMark("@yin__spade") == 0 or player:getMark("@yin__heart") == 0 or player:getMark("@yin__club") == 0  or player:getMark("@yin__diamond") == 0  then
        table.insert(choices1,1, "add_suit")
      end
      local choice1 = room:askForChoice(player, choices1, self.name)
      local choices2 = {}
      if choice1 == "Cancel" then
        return false
      elseif choice1 == "remove_suit" then
        if player:getMark("@yin__spade") > 0 then
          table.insert(choices2, 1,"yin__spade")
        elseif player:getMark("@yin__heart") > 0 then
          table.insert(choices2, 2,"yin__heart")
        elseif player:getMark("@yin__club") > 0 then
          table.insert(choices2,3, "yin__club")
        elseif player:getMark("@yin__diamond") > 0 then
          table.insert(choices2, 4,"yin__diamond")
        end
      elseif choice1 == "add_suit" then
        if player:getMark("@yin__spade") == 0 then
          table.insert(choices2, 1,"yin__spade")
        elseif player:getMark("@yin__heart") == 0 then
          table.insert(choices2,2, "yin__heart")
        elseif player:getMark("@yin__club") == 0 then
          table.insert(choices2, 3,"yin__club")
        elseif player:getMark("@yin__diamond") == 0 then
          table.insert(choices2, 4,"yin__diamond")
        end
      local choice2 = room:askForChoice(player, choices2, self.name)
      self.cost_data = { choice1 , choice2 }
    end
    return true
  end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      local suit = data.card.suit
      if player:getMark("@yin__spade") == 0 and suit == "spade" then
        room:setPlayerMark(player,"@yin__spade",1)
        --room:setCardMark(Fk:getCardById(id), "@@xingchong-inhand", 1)
      elseif player:getMark("@@yin__heart") == 0 and suit == "heart" then
        room:setPlayerMark(player,"@yin__heart",1)
      elseif player:getMark("@yin__club") == 0 and suit == "club" then
        room:setPlayerMark(player,"@yin__club",1)
      elseif player:getMark("@yin__diamond") == 0 and suit == "diamond" then
        room:setPlayerMark(player,"@yin__diamond",1)
    else
      local choice1 =  self.cost_data{1}
      local choice2 =  self.cost_data{2}
      if choice1 == "remove_suit" then
        if choice2 == "yin__spade" then
          room:removeMark(player,"@yin__spade",1)
        elseif choice2 == "yin__heart"  then
          room:removeMark(player,"@yin__heart",1)
        elseif choice2 == "yin__club" then
          room:removeMark(player,"@yin__club",1)
        elseif choice2 == "yin__diamond"  then
          room:removeMark(player,"@yin__diamond",1)
        end
      elseif choice1 == "add_suit" then
        if choice2 == "yin__spade" then
          room:setPlayerMark(player,"@yin__spade",1)
        elseif choice2 == "yin__heart"  then
          room:setPlayerMark(player,"@yin__heart",1)
        elseif choice2 == "yin__club" then
          room:setPlayerMark(player,"@yin__club",1)
        elseif choice2 == "yin__diamond"  then
          room:setPlayerMark(player,"@yin__diamond",1)
        end
      end
    end
    end
  end,
}
  yin__godguozhao:addSkill(yin__pianchong)
  yin__godguozhao:addSkill(yin__zunwei)
  Fk:loadTranslationTable{
  ["yin__godguozhao"] = "神郭照",

  ["yin__pianchong"] = "偏宠",
  [":yin__pianchong"] = "锁定技，当牌被使用时，若此牌的花色已被【尊位】记录的时，你摸一张牌。",
  ["yin__zunwei"] = "尊位",
  [":yin__zunwei"] = "当你成为牌的目标时，若此牌的花色未被记录，则记录此花色，然后取消此目标；回合开始时，你可以增加或移除一种花色记录。",

  ["add_suit"] = "增加花色",
  ["remove_suit"] = "移除花色",

  ["yin__spade"] = "黑桃",
  ["yin__heart"] = "红桃",
  ["yin__club"] = "梅花",
  ["yin__diamond"] = "方块",

  ["@@yin__spade"] = "黑桃",
  ["@@yin__heart"] = "红桃",
  ["@@yin__club"] = "梅花",
  ["@@yin__diamond"] = "方块",
}]]





















return extension